#!/bin/bash
KAFKA_HOME=/disk2/kafka_2.10-0.8.2.2
while true; do
        huineng_processed_offset_total=0
        huineng_latest_offset_total=0
        time=$(date +%s)
        for i in $(cat huineng_offsets)
        do
          huineng_processed_offset=$(echo "get /consumers/huineng-group-7s/offsets/gw-huineng/$i" | $KAFKA_HOME/bin/zookeeper-shell.sh 10.1.235.1,10.1.235.2,10.1.235.15,10.1.235.15,10.1.235.16,10.1.235.17 2>/dev/null | tail -n 1)
          huineng_processed_offset_total=$(expr $huineng_processed_offset_total + $huineng_processed_offset)
        done
        for h in $($KAFKA_HOME/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 10.1.235.5:9092,10.1.235.6:9092,10.1.235.10:9092,10.1.235.11:9092 --time -1 --topic gw-huineng |awk -F '[::]' '{print $3}')
        do
        huineng_latest_offset_total=$(expr $huineng_latest_offset_total + $h)
        done
        echo "put goldwind.kafka.huineng.offset.processed.total $time $huineng_processed_offset_total host=$(hostname -s)"    
        echo "put goldwind.kafka.huineng.offset.latest.total $time $huineng_latest_offset_total host=$(hostname -s)"
        sleep 60
done

